/**   
 * @Title: UpdateCheckCommunicater.java 
 * @Package com.esun.rabbit2.communicaters.update 
 * @Description: (检测升级接口) 
 * @author: Billy Qigs@500wan.com   
 * @date: 2011-11-17 下午2:12:04  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.update;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.DistributionChannels;
import com.esun.config.Key;
import com.esun.network.ServerCommunicater;
import com.esun.util.HashMapUtil;

/**
 * @ClassName: UpdateCheckCommunicater
 * @Description: (检测升级接口)
 * @author: Billy Qigs@500wan.com
 * @date: 2011-11-17 下午2:12:04
 * 
 */
public class UpdateCheckCommunicater extends ServerCommunicater {

	private Context context;

	private String strLatestVersion = "";
	private String strUpdateInfo = "";
	private String strUpdateURL = "";

	public UpdateCheckCommunicater(Context con) {
		context = con;
	}

	public int isUpdateCheckSucceed(String IMEI) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException, NameNotFoundException {

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(HashMapUtil.getMapItem(BussinessCode.PASER_MID, BussinessCode.MID_UPDATE_CHECK));
		list.add(HashMapUtil.getMapItem(BussinessCode.PASER_CK, Config.NULLMARK));
		list.add(HashMapUtil.getMapItem(Key.KEY_CHANNEL, DistributionChannels.QUDAO));
		list.add(HashMapUtil.getMapItem(Key.KEY_VERSION, context.getPackageManager().getPackageInfo(Config.APP_PACKAGE_INFO, 0).versionName));
		list.add(HashMapUtil.getMapItem(Key.KEY_PRODUCT, Config.PRODUCT_NAME));
		list.add(HashMapUtil.getMapItem(Key.KEY_EVENT, Config.ACTION_EVENT));
		list.add(HashMapUtil.getMapItem(Key.KEY_PLATFORM, Config.ANDROID));
		list.add(HashMapUtil.getMapItem(Key.KEY_MBIMEI, IMEI));

		super.getServerResponse(list, true);
		int serverState = super.getState();
		if (serverState == 100) {
			setLatestVersion(super.getResult().get(Key.KEY_VERSION));
			setUpdateInfo(super.getResult().get(Key.KEY_NOTE));
			setUpdateURL(super.getResult().get(Key.KEY_ADDRESS));
		}
		return serverState;
	}

	private void setLatestVersion(String str) {
		strLatestVersion = str;
	}

	public String getLatestVersion() {
		return strLatestVersion;
	}

	private void setUpdateInfo(String str) {
		strUpdateInfo = str;
	}

	public String getUpdateInfo() {
		return strUpdateInfo;
	}

	private void setUpdateURL(String str) {
		strUpdateURL = str;
	}

	public String getUpdateURL() {
		return strUpdateURL;
	}

}
